// 发布文章表单数据验证模块
// 文章标题、内容、发布状态、分类id
// 导入joi
const joi = require('joi')
const title = joi.string().required()
const content = joi.string().required().allow('')
const cateName = joi.string().required()
const tagName = joi.string().required()
const describes = joi.string().required().allow('')
const cover_img = joi
  .string()
  .required()
  .pattern(/^(http|https):\/\/\S*[.jpg|.png|.webp|.jpge]$/)
const create_time = joi.date().required()
const id = joi.number().integer().required()
const curpage = joi.number().min(1)
const pageSize = joi.number().min(5)

// 向外暴露验证规则对象
exports.reg_article_scchema = {
  body: {
    title,
    describes,
    content,
    cateName,
    tagName,
    cover_img,
    create_time
  }
}

exports.reg_getArticle_schema = {
  params: {
    curpage,
    pageSize
  }
}

// 向外暴露删除文章路由的验证规则
exports.reg_deleteArticle_schema = {
  body: {
    id
  }
}

// 向外暴露通过id获取文章路由的验证规则
exports.reg_getArticleById_schema = {
  query: {
    id
  }
}

// 向外暴露修改文章路由的验证规则
exports.red_updateArticle_shema = {
  body: {
    title,
    describes,
    content,
    cateName,
    tagName,
    cover_img,
    create_time,
    id
  }
}
